public class DeleteSPCtlEx {

    Support_Program__c sp;
    public DeleteSPCtlEx(ApexPages.StandardController sc) {
        this.sp = (Support_Program__c)sc.getRecord();
    }
    
    public PageReference DelSP() {
        String spObjType = this.sp.Id;
        spObjType = spObjType.substring(0,3);
        
        Program_Contact__c[] pcArr = [Select Id From Program_Contact__c Where Support_Program__c=:sp.Id];
        Program_Asset__c[] paArr = [Select Id From Program_Asset__c Where Support_Program__c=:sp.Id];
        Entitlement__c[] entArr = [Select Id From Entitlement__c Where Support_Program__c=:sp.Id];
        delete pcArr;
        delete paArr;
        delete entArr;
        delete this.sp;
        
        PageReference pr = new PageReference('/'+spObjType+'/o');
        pr.setRedirect(true);
        return pr;
    }
    
    static testMethod void testDelSP() {
        UT_SObjectFactory.InterconnectedSObjectsForNCSP o = new UT_SObjectFactory.InterconnectedSObjectsForNCSP(true,5);
        ApexPages.StandardController sc = new ApexPages.StandardController(o.sp);
        DeleteSPCtlEx cx = new DeleteSPCtlEx(sc);
        PageReference pr = cx.DelSP();
        System.assertEquals(0,[select count() from Program_Contact__c where Support_Program__c=:o.sp.Id],'All PC objects should have been deleted.');
        System.assertEquals(0,[select count() from Program_Asset__c where Support_Program__c=:o.sp.Id],'All PA objects should have been deleted.');
        System.assertEquals(0,[select count() from Support_Program__c where Id=:o.sp.Id],'SP object should have been deleted.');
    }

}